<?php
namespace App\Services\Recommend;
use App\Services\Recommend\Recommend\RecommendLogic;
/**
 * @Author: ws
 * @Date:   2018-06-12 16:23:45
 * @Last Modified by:   Marte
 */
class Recommend
{
    use \App\Services\Goods\Traits\BaseCheckCate;
    //添加或编辑推荐位分类的时候进行检验分类
    private function _updateRecommend(array $data, bool $isEdit): array
    {
        $checkData = $this->_baseCheckCate($data, '', 'edit',  '\App\Services\Recommend\Recommend\RecommendLogic');
        if($checkData['status'] != SUCCESS_STATUS){
            return $checkData;
        }
        if(isset($data['id'])){
            $res = (new RecommendLogic())->editRecommend($data);
        }else{
            $data['level'] = $data['pid'] ? $checkData['res']['level'] + 1 : 0;
            $res = (new RecommendLogic())->addRecommend($data);
        }
        return $res;
    }

    //添加推荐位分类
    public function addRecommend($data): array
    {
        ValidateRecommend::checkValidate($data, ['app_id','other_app_read','is_public','pid','name','action','profile_pic','desc','order','token']);
        return $this->_updateRecommend($data, false);
    }

    //编辑推荐位分类
    public function editRecommend($data): array
    {
        if (empty($data)) {
            return null_data($data,"参数不能为空！");
        }
        $data = init_array($data,['id'=>0,'app_id'=>11,'other_app_read'=>'','is_public'=>0,'pid'=>0,'name'=>' ','action'=>' ','profile_pic'=>'','desc'=>'','order'=>100]);

        ValidateRecommend::checkValidate($data,['id','app_id','other_app_read','is_public','pid','name','action','profile_pic','desc','order']);
        return $this->_updateRecommend($data, true);
    }

    // 获取本应用下的推荐位分类树
    public function getTree($data): array
    {
        if (empty($data)) {
            return null_data($data,"参数不能为空！");
        }
        $data = init_array($data,['id'=>0,'app_id'=>0]);

        return (new RecommendLogic())->getTree($data);
    }

    /*获取某个不删除的分类详情*/
    public function oneCateInfo($data): array
    {
        if (empty($data)) {
            return null_data($data,"参数不能为空！");
        }
        $data = init_array($data,['id'=>0,'app_id'=>0]);

        return (new RecommendLogic())->oneCateInfo($data);
    }

    /*后台删除某个推荐分类*/
    public function delOneCate($data): array
    {
        if (empty($data)) {
            return null_data($data,"参数不能为空！");
        }
        $data = init_array($data,['id'=>0,'app_id'=>0]);

        return (new RecommendLogic())->delOneCate($data);
    }

//    /*前台获取action所属分类下的子类 多级*/
//    public function getChildByAction(): array
//    {
//        $data = $this->haveIssetReceiveData(['app_id'=>0, 'action'=>' ']);
//        return $this->stepRun($data, 'getChildByAction');
//    }
//
//    /*前台获取action所属分类下的子类 一级*/
//    public function getOneLevChildByAction(): array
//    {
//        $data = $this->haveIssetReceiveData(['app_id'=>0, 'action'=>' ', 'limit'=>0]);
//        return $this->stepRun($data, 'getOneLevChildByAction');
//    }


}
